package designpattern.observe.improve;

import java.util.ArrayList;
import java.util.List;

public class WeatherData implements Subject {

    private float temperature;

    private float pressure;

    private float humidity;

    private List<Observe> observeList;

    public WeatherData() {
        observeList = new ArrayList<>();
    }

    public float getTemperature() {
        return temperature;
    }

    public float getPressure() {
        return pressure;
    }

    public float getHumidity() {
        return humidity;
    }

    public void setData(float temperature, float pressure, float humidity){
        this.temperature = temperature;
        this.pressure = pressure;
        this.humidity = humidity;
        notifyObserve();
    }

    public void dataChange(){
        for(Observe observe:observeList){
            observe.update(temperature,pressure,humidity);
        }

    }
    @Override
    public void register(Observe observe) {
        observeList.add(observe);

    }

    @Override
    public void unRegister(Observe observe) {

        if(observeList.contains(observe)) {
            observeList.remove(observe);
        }

    }

    @Override
    public void notifyObserve() {
        dataChange();
    }
}
